package com.mz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mz.common.dto.PaginationVo;
import com.mz.common.dto.R;
import com.mz.common.utils.PageDataHandlerUtils;
import com.mz.entity.OmsGoodsInfo;
import com.mz.entity.vo.*;
import com.mz.service.OmsGoodsInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.Serializable;
import java.util.List;

/**
 * (OmsGoodsInfo)表控制层
 *
 * @author makejava
 * @since 2023-12-13 13:38:28
 */
@RestController
@RequestMapping("/omsGoodsInfo")
public class OmsGoodsInfoController  {
    /**
     * 服务对象
     */
    @Resource
    private OmsGoodsInfoService omsGoodsInfoService;

    /**
     * 分页查询所有数据
     * @return 所有数据
     */
    @GetMapping("/pagination")
    public R getGoodsPagination(PaginationVo paginationVo, GoodsQuery goodsQuery) throws Exception {

        IPage page =  omsGoodsInfoService.getGoodsPagination( paginationVo, goodsQuery);
        return PageDataHandlerUtils.toR(page);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public R getGoodsDetail(@PathVariable Long id) throws Exception {

        GoodsDetailVo goodsDetailVo = omsGoodsInfoService.getGoodsDetail(id);
        return R.ok( goodsDetailVo );
    }

    /**
     * 新增数据
     * @return 新增结果
     */
    @PostMapping
    public R addGoodsInfo(@RequestBody GoodsVo goodsVo) throws Exception {
        Long goodsId = omsGoodsInfoService.addGoodsInfo( goodsVo );
        return R.ok(goodsId);
    }

    @PutMapping("/productImg")
    public R updateGoodsProductImgVideoList(@RequestBody @Valid GoodsProductImgVo goodsProductImgVo) throws Exception {

        omsGoodsInfoService.updateGoodsProductImgVideoList( goodsProductImgVo );
        return R.ok();
    }

    @PutMapping("/detailImg")
    public R updateGoodsDetailImgList(@RequestBody @Valid GoodsDetailImgVo goodsDetailImgVo) throws Exception {

        omsGoodsInfoService.updateGoodsDetailImgList( goodsDetailImgVo );
        return R.ok();
    }

    @PutMapping("/grounding")
    public R updateGoodsGrouding(@RequestBody @Valid GoodsGroundingVo goodsGroundingVo) throws Exception {

        omsGoodsInfoService.updateGoodsGrouding( goodsGroundingVo );
        return R.ok();
    }


    /**
     * 修改数据
     *
     * @param omsGoodsInfo 实体对象
     * @return 修改结果
     */
    @PutMapping
    public R update(@RequestBody OmsGoodsInfo omsGoodsInfo) {
        return null; //successsuccess(this.omsGoodsInfoService.updateById(omsGoodsInfo));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @PostMapping("/remove")
    public R removeGoods(@RequestBody List<Long> idList) throws Exception {

        omsGoodsInfoService.removeGoods(idList);
        return R.ok();
    }
}

